package controller

import (
	"context"
	"github.com/gin-gonic/gin"
	log "github.com/micro/go-micro/v2/logger"
	"rpc-protos/product/pb"
	"strconv"
	"web-service/admin-api/middleware"
)

/**
 * 管理员
 */
type AdminController struct {
	BaseController
}

/**
 * 获取查询列表
 */
func (ctrl *AdminController) Login(ctx *gin.Context) {

	//GET方式获取query string
	sizeStr := ctx.DefaultQuery("size", "10")
	size, _ := strconv.Atoi(sizeStr)
	//大写的原因,需要把小写的转义一下
	var prodReq pb.ProdRequest
	prodReq.Size = int32(size)

	prodRpcClient := middleware.GetProductRpcClient()
	prodResp, _ := prodRpcClient.GetProductList(context.Background(), &prodReq)

	log.Info("prodService.GetProdList:", prodResp)
	ctrl.ResponseData(ctx, prodResp.Data)
}
